<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Post extends Model
{
    use SoftDeletes;
    protected $fillable = ['title','post_slug','post_thumb','post_jump_url','post_author',
        'post_source','post_date','post_template','comment_status','post_sort','post_status',
        'post_read_num','post_content','parent_id','post_password','post_type'
    ];

    public function manyCategory()
    {
        return $this->belongsToMany(Category::class,'posts_category','post_id','category_id');
    }

    public function manyTag()
    {
        return $this->belongsToMany(Tag::class,'posts_tags','post_id','tag_id');
    }

    public function meta()
    {
        return $this->hasMany(PostMeta::class,'post_id','id');
    }


    //子分类
    public function childs()
    {
        return $this->hasMany(Post::class,'parent_id','id');
    }
    //所有子类
    public function allChilds()
    {
        return $this->childs()->with('allChilds');
    }
}
